package com.example.dw.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.dw.entity.Certificate;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 证书Mapper接口
 * @author system
 * @since 2024-01-01
 */
@Mapper
public interface CertificateMapper extends BaseMapper<Certificate> {

    /**
     * 根据姓名和身份证号查询证书
     */
    @Select("SELECT * FROM certificate WHERE name = #{name} AND certificateid_sfz = #{certificateidSfz}")
    List<Certificate> findByNameAndIdCard(@Param("name") String name, @Param("certificateidSfz") String certificateidSfz);

    /**
     * 根据证书编号查询证书
     */
    @Select("SELECT * FROM certificate WHERE certificateid_bh = #{certificateidBh}")
    List<Certificate> findByCertificateId(@Param("certificateidBh") String certificateidBh);

    /**
     * 根据手机号查询证书
     */
    @Select("SELECT * FROM certificate WHERE phone = #{phone}")
    List<Certificate> findByPhone(@Param("phone") String phone);

    /**
     * 多条件查询证书
     */
    @Select("<script>" +
            "SELECT * FROM certificate WHERE 1=1" +
            "<if test='name != null and name != \"\"'>" +
            " AND name = #{name}" +
            "</if>" +
            "<if test='certificateidSfz != null and certificateidSfz != \"\"'>" +
            " AND certificateid_sfz = #{certificateidSfz}" +
            "</if>" +
            "<if test='phone != null and phone != \"\"'>" +
            " AND phone = #{phone}" +
            "</if>" +
            "<if test='certificateidBh != null and certificateidBh != \"\"'>" +
            " AND certificateid_bh = #{certificateidBh}" +
            "</if>" +
            " ORDER BY createdAt DESC" +
            "</script>")
    List<Certificate> searchCertificate(@Param("name") String name,
                                        @Param("certificateidSfz") String certificateidSfz,
                                        @Param("phone") String phone,
                                        @Param("certificateidBh") String certificateidBh);
} 